<?php

Yii::import('application.models._base.BaseYearReport');

class YearReport extends BaseYearReport {

    public $subtotalyearwise;
    public $subtotalstatewise;

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public static function countYearwisedate($state, $year) {
        $yeardata = YearReport::model()->findByAttributes(array('state' => $state, 'year' => $year));
        echo $yeardata->ccount;
    }

    public static function countYearwisedateGender($state, $year) {
        $yeardata = YearReport::model()->findByAttributes(array('state' => $state, 'year' => $year));
        echo $yeardata->ccount;
    }

    public static function mailCounter($gender, $year, $state) {
        $criteria = new CDbCriteria();
        $criteria->condition = 'Gender="' . $gender . '" AND LEFT(Call_date,4)=' . $year . ' AND State="' . $state . '"';
        $yeardata = ComplaintMaster::model()->findAll($criteria);

        return count($yeardata);
    }

    public static function femailCounter($gender, $year, $state) {
        $criteria = new CDbCriteria();
        $criteria->condition = 'Gender="' . $gender . '" AND LEFT(Call_date,4)=' . $year . ' AND State="' . $state . '"';
        $yeardata = ComplaintMaster::model()->findAll($criteria);
        return count($yeardata);
    }

    public static function groupByYear() {
        $criteria = new CDbCriteria();
        $criteria->group = 'year';
        $criteria->order = 'year ASC';
        return YearReport::model()->findAll($criteria);
    }

    public static function groupByState() {
        $criteria = new CDbCriteria();
        $criteria->group = 'state';
        $criteria->order = 'state ASC';
        return YearReport::model()->findAll($criteria);
    }

    public static function subtotalreport($state) {
        $criteria = new CDbCriteria;
        $criteria->select = 'SUM(ccount) as subtotalyearwise';
        $criteria->addCondition('state="' . $state . '"');
        $user = YearReport::model()->find($criteria);
        echo $user->subtotalyearwise;
    }

    public static function subtotalreportstate($state, $year) {
        $criteria = new CDbCriteria;
        $criteria->condition = 'LEFT(Call_date,4)=' . $year . ' AND State="' . $state . '"';
        $user = ComplaintMaster::model()->find($criteria);

        return count($user);
    }

    public static function yearwisegenderqunetr($gender, $year) {
        $criteria = new CDbCriteria;
        $criteria->condition = 'Gender="' . $gender . '" AND LEFT(Call_date,4)=' . $year;
        $yeardata = ComplaintMaster::model()->findAll($criteria);
        return count($yeardata);
    }
     public static function totalCountreportgenderwise() {
       
        $yeardata = ComplaintMaster::model()->findAll();
        return count($yeardata);
    }

    public static function totalCountBYYear($year) {
        $criteria = new CDbCriteria;
        $criteria->select = 'SUM(ccount) as subtotalstatewise';
        $criteria->addCondition('year="' . $year . '"');
        $criteria = YearReport::model()->find($criteria);
        echo $criteria->subtotalstatewise;
    }

    public static function totalReportCount() {
        $criteria = new CDbCriteria;
        $criteria->select = 'SUM(ccount) as subtotalstatewise';
        $criteria = YearReport::model()->find($criteria);
        echo $criteria->subtotalstatewise;
    }

}
